<template>
  <div v-loading.lock="loading" class="base-content">
    <div class="basic-info">
      <div class="base-content-operate">
        <el-button icon="el-icon-plus" type="primary" @click="onNew">{{
          operateType.add
        }}</el-button>
      </div>

      <el-table
        class="filter unsetborder"
        :class="{ 'show-filter': showFilterRow }"
        :data="list"
        element-loading-text="Loading"
        fit
        height="250"
        highlight-current-row
      >
        <el-table-column align="center">
          <template #header>
            <div class="filter-icon" :title="operateType.screen">
              <SvgIcon
                class-name="filter"
                icon-class="filter"
                @click="filterIconClick"
              />
            </div>
          </template>
          <el-table-column width="50"></el-table-column>
        </el-table-column>
        <el-table-column
          :label="sysBusinessReportDict.serialNumber"
          align="center"
        >
          <el-table-column width="100" align="center">
            <template slot-scope="scope">{{ scope.$index + 1 }}</template>
          </el-table-column>
        </el-table-column>
        <el-table-column :label="sysBusinessReportDict.dictionaryCoding">
          <el-table-column prop="dictCode">
            <template #header>
              <el-input
                v-if="showFilterRow"
                v-model="queryForm.dictCode"
                @keyup.enter.native="onQuery"
              ></el-input>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column :label="sysBusinessReportDict.dictionaryName">
          <el-table-column prop="dictName">
            <template #header>
              <el-input
                v-if="showFilterRow"
                v-model="queryForm.dictName"
                @keyup.enter.native="onQuery"
              ></el-input>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column :label="sysBusinessReportDict.describe">
          <el-table-column prop="description">
            <template #header>
              <el-input
                v-if="showFilterRow"
                v-model="queryForm.description"
                @keyup.enter.native="onQuery"
              ></el-input>
            </template>
          </el-table-column>
        </el-table-column>

        <el-table-column :title="operateType.action">
          <template slot-scope="scope">
            <div class="base-table-operation">
              <el-link
                size="mini"
                type="primary"
                @click="handleEdit(scope.row)"
                >{{ operateType.redact }}</el-link
              >
              <el-link
                size="mini"
                type="danger"
                @click="handleDelete(scope.row)"
                >{{ operateType.delete }}</el-link
              >
            </div>
          </template>
        </el-table-column>
      </el-table>

      <BasePagination
        :total="pagination.total"
        :current-page="pagination.pageIndex"
        :page-count="pagination.total"
        @changePage="changePage"
        @sizeChange="sizeChange"
      />
    </div>

    <SysBusinessReportDictEdit
      ref="SysBusinessReportDictEdit"
      :dialog-form-visible.sync="dialogFormVisible"
    />
  </div>
</template>

<script>
import {
  deleteRecord,
  getList,
} from "../../../api/SysBusiness/SysBusinessReportDict.js";
import SysBusinessReportDictEdit from "./SysBusinessReportDictEdit.vue";

export default {
  name: "SysBusinessReportDictList",
  components: { SysBusinessReportDictEdit },
  data() {
    return {
      loading: true,
      list: [],
      queryForm: {
        dictCode: "",
        dictName: "",
        description: "",
      },
      dialogFormVisible: false,
      pagination: {
        pageIndex: 1,
        pageSize: 10,
        total: 0,
      },
    };
  },
  computed: {
    operateType() {
      return this.$t("ModuleSysBusiness.OperateType") || {};
    },
    sysBusinessReportDict() {
      return this.$t("SysBusinessReportDict") || {};
    },
  },
  created() {
    this.getList();
  },
  methods: {
    changePage(val) {
      this.pagination.pageIndex = val;
      this.getList();
    },
    sizeChange(val) {
      this.pagination.pageIndex = 1;
      this.pagination.pageSize = val;
      this.getList();
    },
    cancelForm() {
      this.$refs.queryForm.resetFields();
      this.pagination.pageIndex = 1;
      this.getList();
    },
    getList() {
      this.loading = true;
      getList(this.queryForm, this.pagination)
        .then((res) => {
          this.list = res.data.dataList ? res.data.dataList : [];
          this.pagination.total = res.data.total;
          this.loading = false;
        })
        .catch(() => {
          this.loading = false;
        });
    },
    onNew() {
      this.$refs.SysBusinessReportDictEdit.formData = this.Helper.deepCopy(
        this.$refs.SysBusinessReportDictEdit.initData
      );
      this.dialogFormVisible = true;
    },
    handleDelete(rowData) {
      this.Helper.deleteConfirm(() => {
        this.loading = true;
        deleteRecord({ id: rowData.id })
          .then((res) => {
            this.getList();
            this.loading = false;
          })
          .catch(() => {
            this.loading = false;
          });
      });
    },
    handleEdit(rowData) {
      this.$refs.SysBusinessReportDictEdit.formData = rowData;
      this.dialogFormVisible = true;
    },
    onQuery() {
      this.getList();
    },
  },
};
</script>
